﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:VSTalk.Engine.Controls"
                    xmlns:conerters="clr-namespace:VSTalk.Engine.Converters">
    <conerters:InterlocutorStateToColorConverter x:Key="InterlocutorStateToColorConverter" />
    <conerters:VisibleIfFalseConverter x:Key="VisibleIfFalseConverter" />

    <Style TargetType="{x:Type controls:InterlocutorLabel}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:InterlocutorLabel}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Ellipse Grid.Column="0"
                                 Name="StateEllipse"
                                 Width="10"
                                 Height="10"
                                 Margin="5">
                            <Ellipse.Fill>
                                <MultiBinding Converter="{StaticResource InterlocutorStateToColorConverter}" >
                                    <Binding Path="Context.State" RelativeSource="{RelativeSource TemplatedParent}" />
                                    <Binding Path="Context.Show" RelativeSource="{RelativeSource TemplatedParent}"/>
                                </MultiBinding>
                            </Ellipse.Fill>
                        </Ellipse>
                        <TextBlock Grid.Column="1"
                                   Margin="5"
                                   Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Interlocutor.Name}" />
                        <Rectangle Name="IsSubscribed"
                                   Fill="Red"
                                   Grid.Column="2"
                                   Height="7"
                                   Width="7"
                                   Margin="0,0,5,0"
                                   Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Interlocutor.Subscribed, Converter={StaticResource VisibleIfFalseConverter}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Counter.HasMessages}"
                                     Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="StateEllipse"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="1.0"
                                                         To="0.0"
                                                         Duration="0:0:0.3"
                                                         AutoReverse="True"
                                                         RepeatBehavior="Forever" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard FillBehavior="Stop">
                                        <DoubleAnimation Storyboard.TargetName="StateEllipse"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1"
                                                         Duration="0:0:0.1" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>